﻿// filepreview.js => $_global_filepreview() => previewBase.getHtml();
// clienttemplates.js => if (viewCtx.ListSchema.IsDocLib) => EnsureScriptFunc("filePreview.js", "filePreviewManager", onDependenciesLoaded);
// clienttemplates.js => callout.listItemPreviewer = filePreviewManager.createPreviewFromListItem(renderCtx, listItem);
// clienttemplates.js => var previewMarkup = callout.listItemPreviewer.getHtml();

'use strict';


SP.SOD.executeOrDelayUntilScriptLoaded(getlist, "core.js");

function getlist() {
    var url = _spPageContextInfo.webAbsoluteUrl +
                "/_api/web/lists(" + _spPageContextInfo.pageListId + ")";

    $.ajax({
        url: url,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },

    }).done(function (data) {
        alert(data.d.Title);
    }).fail(function () {

    });
}

function getlistItem() {    
    var url = _spPageContextInfo.webAbsoluteUrl +
                "/_api/Web/Lists/getByTitle('Digital%20Asset')" +
                "/items(" + $.getUrlParam("ID") + ")";
    $.ajax({
        url: url,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },

    }).done(function (data) {
        alert(data.d.Title);
    }).fail(function () {

    });
    

    //var context = SP.ClientContext.get_current();
    //var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
    //var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
    //item = list.getItemById($.getUrlParam("ID"));
    //context.load(list);
    //context.executeQueryAsync(onLoadItemSuccess, onLoadItemFail);
}



//function onLoadItemSuccess() {
//}

//function onLoadItemFail(sender, args) {
//    alert('Failed to get item. Error:' + args.get_message());
//}

//EnsureScriptFunc("filePreview.js", "filePreviewManager", onDependenciesLoaded);

//function onDependenciesLoaded() {
//    var listItemPreviewer = filePreviewManager.createPreviewFromListItem(renderCtx, listItem);
//    var previewMarkup = listItemPreviewer.getHtml()
//}

$.extend({
    getUrlParams: function () {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlParam: function (name) {
        return $.getUrlParams()[name];
    }
});